package com.cn.demo4.service.impl;

import com.cn.demo4.entity.CompanyEntity;
import com.cn.demo4.mapper.CompanyMapper;
import com.cn.demo4.service.ICompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;

import java.util.List;

@Service
public class CompanyServiceImpl implements ICompanyService {
    @Autowired
    private CompanyMapper companyMapper;
    @Override
    public List<CompanyEntity> findAll(CompanyEntity companyEntity) {
        return companyMapper.findAll(companyEntity);
    }

    @Override
    public CompanyEntity findById(Integer id) {
        return companyMapper.findById(id);
    }

    @Override
    public String update(CompanyEntity companyEntity) {
        int result = companyMapper.update(companyEntity);
        if(result == 1) {
            Jedis jedis = new Jedis();
            jedis.flushDB();
        }
        return result == 1 ? "success" : "error";
    }

    @Override
    public String add(CompanyEntity companyEntity) {
        int result = companyMapper.add(companyEntity);
        if (result == 1) {
            Jedis jedis = new Jedis();
            jedis.flushDB();
        }
        return result == 1 ? "success" : "error";
    }

    @Override
    public int del(Integer id) {
        int result = companyMapper.del(id);
        if (result == 1) {
            Jedis jedis = new Jedis();
            jedis.flushDB();
        }
        return result;
    }

    @Override
    public int getCount(CompanyEntity companyEntity) {
        return companyMapper.getCount(companyEntity);
    }

    @Override
    public CompanyEntity getCompanyModelForHome() {
        return companyMapper.getCompanyModelForHome();
    }
}
